package org.example.mybaties.model;

import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {


    @ResultMap("resultMap")
    @Select("select * from userInfo")
    List<UserInfo> getUserInfoAll();


    @Select("select id, username, password, age, gender, phone, "+ "delete_flag as deleteFlag," +
          " create_Time as createTime, update_time as updateTime  from userInfo")
    List<UserInfo> selectUserInfos();

    @Select("select * from userInfo")
    List<UserInfo> getUserInfo3();


    @Select("select * from userinfo where delete_flag = #{deleteFlag}")
    List<UserInfo> getUserInfoByDeleteFlag(Integer deleteFlag);


    @Select("select * from userinfo where delete_flag = #{deleteFlag} and gender = #{gender}")
    UserInfo getUserInfo2(Integer deleteFlag, Integer gender);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into userinfo (username, password, age, gender) values(#{username}, #{password}, #{age}, #{gender})")
    Integer insert(UserInfo userInfo);


  //@Options(useGeneratedKeys = true,keyProperty = "id")
  @Insert("insert into userinfo (username, password, age, gender)  " +
          "values (#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender})")
  Integer insert2(@Param("userInfo") UserInfo userInfo);



  //删除操作
  @Delete("delete from userInfo where id = #{id}")
  Integer delete(Integer id);

  //更新操作
  @Update("update userinfo set password = #{password}, age = #{age}, gender = #{gender} where id = #{id}")
  Integer update(UserInfo userInfo);


}
